Fix aws_cloudfrontkeyvaluestore_keys_exclusive value JSON encoding bug#46900
Conversation
Fixes hashicorp#46899 When the resource was refactored to use AutoFlEx, the flex.Expand/flex.Flatten functions introduced JSON encoding/decoding of string values. This caused values to be stored in AWS with extra quotes (e.g., "hello" stored as "\"hello\""). The bug was masked in tests because: - flex.Expand JSON-encodes values during Create/Update - flex.Flatten JSON-decodes values during Read - This symmetrical encode/decode cycle made Terraform state appear correct - Tests only verified Terraform state, not actual AWS values Changes: - Manually set Value fields in syncKeyValuePairs() after flex.Expand to avoid JSON encoding - Manually set Value fields in Read() after flex.Flatten to avoid JSON decoding - Added testAccCheckKeysExclusiveHasValues() helper to verify actual AWS values - Added TestAccCloudFrontKeyValueStoreKeysExclusive_specialCharacters test This is the same bug that was fixed in aws_cloudfrontkeyvaluestore_key resource in PR hashicorp#46898.
Community GuidelinesThis comment is added to every new Pull Request to provide quick reference to how the Terraform AWS Provider is maintained. Please review the information below, and thank you for contributing to the community that keeps the provider thriving! 🚀 Voting for Prioritization
Pull Request Authors
|
YakDriver
left a comment
There was a problem hiding this comment.
LGTM 🎉
% make t T=TestAccCloudFrontKeyValueStoreKey_ K=cloudfrontkeyvaluestore
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
make: Running acceptance tests on branch: 🌿 f-cloudfrontkeyvaluestore-keys-exclusive-value-encoding-fix 🌿...
TF_ACC=1 go1.25.8 test ./internal/service/cloudfrontkeyvaluestore/... -v -count 1 -parallel 20 -run='TestAccCloudFrontKeyValueStoreKey_' -timeout 360m -vet=off
2026/03/17 16:54:50 Creating Terraform AWS Provider (SDKv2-style)...
2026/03/17 16:54:50 Initializing Terraform AWS Provider (SDKv2-style)...
=== RUN TestAccCloudFrontKeyValueStoreKey_Identity_basic
=== PAUSE TestAccCloudFrontKeyValueStoreKey_Identity_basic
=== RUN TestAccCloudFrontKeyValueStoreKey_Identity_ExistingResource_basic
=== PAUSE TestAccCloudFrontKeyValueStoreKey_Identity_ExistingResource_basic
=== RUN TestAccCloudFrontKeyValueStoreKey_Identity_ExistingResource_noRefreshNoChange
=== PAUSE TestAccCloudFrontKeyValueStoreKey_Identity_ExistingResource_noRefreshNoChange
=== RUN TestAccCloudFrontKeyValueStoreKey_basic
=== PAUSE TestAccCloudFrontKeyValueStoreKey_basic
=== RUN TestAccCloudFrontKeyValueStoreKey_mutex
=== PAUSE TestAccCloudFrontKeyValueStoreKey_mutex
=== RUN TestAccCloudFrontKeyValueStoreKey_value
=== PAUSE TestAccCloudFrontKeyValueStoreKey_value
=== RUN TestAccCloudFrontKeyValueStoreKey_disappears
=== PAUSE TestAccCloudFrontKeyValueStoreKey_disappears
=== CONT TestAccCloudFrontKeyValueStoreKey_Identity_basic
=== CONT TestAccCloudFrontKeyValueStoreKey_mutex
=== CONT TestAccCloudFrontKeyValueStoreKey_Identity_ExistingResource_noRefreshNoChange
=== CONT TestAccCloudFrontKeyValueStoreKey_basic
=== CONT TestAccCloudFrontKeyValueStoreKey_disappears
=== CONT TestAccCloudFrontKeyValueStoreKey_value
=== CONT TestAccCloudFrontKeyValueStoreKey_Identity_ExistingResource_basic
--- PASS: TestAccCloudFrontKeyValueStoreKey_mutex (30.04s)
--- PASS: TestAccCloudFrontKeyValueStoreKey_disappears (35.60s)
--- PASS: TestAccCloudFrontKeyValueStoreKey_basic (46.37s)
--- PASS: TestAccCloudFrontKeyValueStoreKey_Identity_basic (46.46s)
--- PASS: TestAccCloudFrontKeyValueStoreKey_value (55.44s)
--- PASS: TestAccCloudFrontKeyValueStoreKey_Identity_ExistingResource_noRefreshNoChange (297.70s)
--- PASS: TestAccCloudFrontKeyValueStoreKey_Identity_ExistingResource_basic (302.52s)
PASS
ok github.com/hashicorp/terraform-provider-aws/internal/service/cloudfrontkeyvaluestore 309.449s|
Warning This Issue has been closed, meaning that any additional comments are much easier for the maintainers to miss. Please assume that the maintainers will not see them. Ongoing conversations amongst community members are welcome, however, the issue will be locked after 30 days. Moving conversations to another venue, such as the AWS Provider forum, is recommended. If you have additional concerns, please open a new issue, referencing this one where needed. |
|
This functionality has been released in v6.37.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you! |
Fixes #46899
Description
This PR fixes a bug in the
aws_cloudfrontkeyvaluestore_keys_exclusiveresource where string values were being incorrectly JSON-encoded, resulting in extra quotes being stored in AWS.Root Cause
When the resource was refactored to use AutoFlEx, the
flex.Expandandflex.Flattenfunctions introduced JSON encoding/decoding of string values. This caused values to be stored in AWS with extra quotes. For example, a configured value of"hello"would be stored in AWS as"\"hello\""(displayed as"hello"with quotes in the console).The bug was masked in tests because:
flex.ExpandJSON-encodes values during Create/Update operationsflex.FlattenJSON-decodes values during Read operationsChanges
Bug Fix
flex.Expandcalls insyncKeyValuePairs()method to prevent JSON encodingflex.Flattencalls inRead()method to prevent JSON decodingTesting Improvements
testAccCheckKeysExclusiveHasValues()helper function that directly calls AWS API to verify stored valuesTestAccCloudFrontKeyValueStoreKeysExclusive_specialCharacterstest case with special characters (quotes, braces, backslashes)Testing
Ran acceptance tests with real AWS resources:
TestAccCloudFrontKeyValueStoreKeysExclusive_specialCharacters- PASS (26.53s)TestAccCloudFrontKeyValueStoreKeysExclusive_value- PASS (34.83s)Related Work
This is the same bug that was fixed in the
aws_cloudfrontkeyvaluestore_keyresource in PR #46898.Changelog